@import '../_error';

// map的连续操作
// way是最外层map操作要用到的方式，如map-get，还是map-has-key
// 所以允许填写值：get和has
@function ivs-m-handle($way, $map, $params...) {
	@if $way != 'get' {
		@if $way != 'has' {
			@return ivs-error('e06');
		}
	};
	$res: $map;
	$len: if($way!='has',length($params), length($params) - 1);
	// @error $params $len;
	@for $i from 1 through $len {
		$val: nth($params, $i);
		$type: type-of($val);
		// @error $type;
		@if $type == list {
			$val: ivs-m-handle('get', nth($val, 1), id);
			$type: type-of($val);
		}
		@if $type == map {
			$res: map-get($val, $res);
		} @else {
			$res: map-get($res, $val);
		}
	}
	@if $way == 'has' {
		$last: nth($params, length($params));
		$type: $last;
		@if($type == map and $res != null) {
			$res: map-has-key($last, $res);			
		}@else{
			$res: map-has-key($res, $last);
		}
	}
	@return $res;
}




